const App = getApp();
Component({
    properties: {
        monthIndex: Number,
        yearIndex: Number,
        seasonIndex: Number,
        searchType: String,
    },
    data: {
        conditionSearch: false
    },
    /**
     * 生命周期函数--监听页面显示
     */
    ready() {
        console.log(this.properties)
        let _this = this;
        App._get('index/searches', {}, function (result) {
                _this.setData(result.data);
                _this.onChange()
            }
        );

    },

    methods: {
        conditionSearchToggle() {
            this.setData({"conditionSearch": !this.data.conditionSearch})
            this.triggerEvent('ontoggle', this.data)
        },

        selectYearConfirm({detail}) {
            console.log(detail)
            this.setData({yearIndex: detail.value})
            this.onChange()
        },
        selectMonthConfirm({detail}) {
            console.log(detail)
            this.setData({monthIndex: detail.value})
            this.onChange()
        },
        selectSeasonConfirm({detail}) {
            this.setData({seasonIndex: detail.value})
            this.onChange()
        },
        searchByMonth() {
            this.setData({searchType: 'month'})
            this.onChange()
        },
        searchBySeason() {
            this.setData({searchType: 'season'})
            this.onChange()
        },
        searchByYear() {
            this.setData({searchType: 'year'})
            this.onChange()
        },
        onChange() {
            this.triggerEvent('onchange', this.data)
            this.setData({conditionSearch: false})
        }
    }
});
